package com.example.replacebooks.controller;

import com.example.replacebooks.common.Result;
import com.example.replacebooks.entity.Class;
import com.example.replacebooks.entity.Notice;
import com.example.replacebooks.entity.Params;
import com.example.replacebooks.service.ClassService;
import com.example.replacebooks.service.NoticeService;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin //解决跨域问题
@RestController
@RequestMapping("/notice")
public class NoticeController {

    private static final Logger log = LoggerFactory.getLogger(NoticeController.class);

    @Resource
    private NoticeService noticeService;

    @GetMapping
    public Result findAll(){return Result.success(noticeService.findAll());}

    @GetMapping("/search")
    public Result findBySearch(Params params){
        PageInfo<Notice> info = noticeService.findBySearch(params);
        return Result.success(info);
    }

    @PostMapping("/add")
    public Result add(@RequestBody Notice notice){
        noticeService.add(notice);
        return Result.success();
    }

    @DeleteMapping("/{noticeid}")
    public Result delete(@PathVariable Integer noticeid){
        noticeService.delete(noticeid);
        return Result.success();
    }
}
